<?
    if (!isset($id)) $id = 0;
    if (!isset($page)) $page = 0;
    $id += 0;
    if ($id == 0)
    {
    ?>
    <div class="breadcrumb">
        <a href="/" title="<?php echo get_title(); ?>">Trang chủ</a> &raquo; <span>Dịch vụ</span>
    </div>
    <div class="box_title">
        <h1>Dịch vụ</h1>
    </div>
    <div class="box-container">
        <?
            $cg = 0;
            $query      =   "SELECT a.* FROM cms as a, cms_menu as b WHERE a.cat = b.id AND b.cat = 'dich_vu' AND a.hien_thi = 1 AND b.hien_thi = 1 ";
            $page       =   $page + 0;
            $perpage    =   get_bien("tin_tuc_show");
            $r_all      =   $db->query($query);
            $sum        =   $db->num_rows($r_all);
            $pages      =   ($sum-($sum%$perpage))/$perpage;
            if ($sum % $perpage <> 0 )  $pages = $pages+1;
            $page       =   ($page==0)?1:(($page>$pages)?$pages:$page);
            $min        =   abs($page-1) * $perpage;
            $max        =   $perpage;
            $q1         =   $db->query($query." ORDER BY a.time DESC LIMIT ".$min.", ".$max);;
            $cg = 0;
            if($db->num_rows($q1) != 0)
            {
                while ($r1 = $db->fetch($q1))
                {
                    $cg ++;
            ?>
            <div class='tin_moi_list' <?=($cg % 2 == 0)?"style='padding-left:15px;'":"style=''"?>>
                <div style='padding-bottom:10px;' class="name"><a href='/dich-vu-xem/<?=$r1['id']?>/<?=lg_string::get_link($r1['ten'])?>'><?=$r1['ten']?></a></div>
                <div class='img_tin'><a href="/dich-vu-xem/<?=$r1['id']?>/<?=lg_string::get_link($r1['ten'])?>"><img src='/uploads/cms/cms_<?=$r1['hinh']?>' /></a></div>
                <div class='tom_tat_tin_moi'>
                    <?=lg_string::crop($r1['chu_thich'],50)?>
                </div>
            </div>
            
        <?
                }
            }
            echo "<div class='clearfix'></div>";
            showPageNavigation($page, $pages, '/dich-vu/'.$id.'/');
        ?>
    </div>
    <?
    }
    else
    {
        $q = $db->query("SELECT * FROM cms_menu WHERE id = '".$id."'");
        if ($r = $db->fetch($q)) {
        ?>
            <div class="breadcrumb">
                <a href="/" title="<?php echo get_title(); ?>">Trang chủ</a> &raquo; <a href="<?php echo lg_string::get_link("dich-vu")?>">Dịch vụ</a> <?php echo get_cms_breadcrumb($r['id']); ?>
            </div>
            <div class="box_title">
                <h1><?=$r['ten']?></h1>
            </div>
            <div class="box-container">
            <?
                $cg = 0;
                $query      =   "SELECT a.* FROM cms as a, cms_menu as b WHERE a.cat = b.id AND b.cat = 'dich_vu' AND a.hien_thi = 1 AND b.hien_thi = 1 AND b.id = '".$id."' ";
                $page       =   $page + 0;
                $perpage    =   get_bien("tin_tuc_show");
                $r_all      =   $db->query($query);
                $sum        =   $db->num_rows($r_all);
                $pages      =   ($sum-($sum%$perpage))/$perpage;
                if ($sum % $perpage <> 0 )  $pages = $pages+1;
                $page       =   ($page==0)?1:(($page>$pages)?$pages:$page);
                $min        =   abs($page-1) * $perpage;
                $max        =   $perpage;
                $q1         =   $db->query($query." ORDER BY a.time DESC LIMIT ".$min.", ".$max);;
                $cg = 0;
                if($db->num_rows($q1) != 0)
                {
                    while ($r1 = $db->fetch($q1))
                    {
                        $cg ++;
                ?>
                <div class='tin_moi_list' <?=($cg % 2 == 0)?"style='padding-left:15px;'":"style=''"?>>
                    <div style='padding-bottom:10px;' class="name"><a href='/dich-vu-xem/<?=$r1['id']?>/<?=lg_string::get_link($r1['ten'])?>'><?=$r1['ten']?></a></div>
                    <div class='img_tin'><a href="/dich-vu-xem/<?=$r1['id']?>/<?=lg_string::get_link($r1['ten'])?>"><img src='/uploads/cms/cms_<?=$r1['hinh']?>' /></a></div>
                    <div class='tom_tat_tin_moi'>
                        <?=lg_string::crop($r1['chu_thich'],50)?>
                    </div>
                </div>
                
                <?
                    }
                } else {
                    echo "Dịch vụ đang được cập nhật";
                }
                echo "<div class='clearfix'></div>";
                showPageNavigation($page, $pages, '/dich-vu/'.$id.'/');
            ?>
        </div>
        <?
        } else {
        ?>
            <div class="breadcrumb">
                <a href="/" title="<?php echo get_title(); ?>">Trang chủ</a> &raquo; <a href="<?php echo lg_string::get_link("dich-vu")?>">Dịch vụ</a> 
            </div>
            <div class="box-container">
                Dịch vụ không tồn tại
            </div>
        <?
        }
    }
?>
